import mammoth

file_src = "./equation.docx"

with open(file_src, "rb") as file:  # 以二进制模式打开文件
    html_content = mammoth.convert_to_html(file)

html_template = """
 <!DOCTYPE html>
 <html>
 <head>
 <meta charset="utf-8">
 <title>TroyOcr</title>
 <style>table, th, td {{border: 1px solid black;}}</style> 
 <script type="text/javascript" async
  src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-MML-AM_CHTML" async>
</script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({{
    tex2jax: {{
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      displayMath: [ ['$$','$$'], ["\\[","\\]"] ]
    }}
  }});
</script>
    
 </head>
 <body>
 {html_partial}
 </body>
 </html>     
 """

with open('test_.html', 'w') as f:
    f.write(html_template.format(html_partial=html_content.value))



